#!/bin/bash

if [ "$1" = "" ] || [ "$2" = "" ] || ! [ "$UID" = "0" ]; then
    echo "用法:"
    echo "  sudo $0 <socks代理IP> <要代理的exe名称>"
    echo
    echo "例如:"
    echo "  sudo $0 192.168.122.169 Wow.exe"
    exit 1
fi

proxy_ip="$1"      # socks代理IP
proxy_exe="$2"     # 要代理的exe名称

pwd="$(dirname "$0")"

trap "$pwd/jiasuqi-stop.sh '$proxy_ip' '$proxy_exe'; echo '代理已停止。'; exit" HUP INT QUIT TERM PIPE

$pwd/jiasuqi-start.sh "$proxy_ip" "$proxy_exe"

# jiasuqi-start.sh 意外退出时执行
$pwd/jiasuqi-stop.sh "$proxy_ip" "$proxy_exe"
echo '代理已停止。'
